<?php
	require('../../inc/config.php');
	$item_menu[0] = 'News';
	$item_menu[1] = 'news';

    $title = 'Newsletter';
	
	include('../header.php');

	//if (!isset($_SESSION["admin"])) {redirect(ADMIN."login.php");	exit(); }

	if(!empty($_SESSION['Msg'])) {
	   echo mensaje_ok($_SESSION['Msg']);
		$_SESSION['Msg']='';
	}

    $de_donde     = '';
pr($Config,1);
	
	$id           = request('id',0);
	$accion       = request('accion','listar');

	switch ($accion) {
		case 'estado': /******************************************************************************** ESTADO *********************/
			$rs = $db->SelectLimit("select * from publicaciones where id='$id'", 1);
			$x	= $rs->FetchRow();

			if ($x['activo']==1) {$x['activo']=0;} else {$x['activo']=1;}

			$ok		= $db->Execute("update publicaciones set activo={$x['activo']} where id='$id'");
			$accion = 'listar';
			break;

		case 'duplicar': /******************************************************************************** DUPLICAR *********************/
			$rs = $db->SelectLimit("select * from publicaciones where id='$id'", 1);
			$x	= $rs->FetchRow();

			$x['id']         = 0;
			$x['activo']     = 0;
			$x['fecha']      = time();
			$x['modificado'] = time();

			$ok = $db->Autoexecute('publicaciones', $x,'INSERT'); 

			$accion = 'listar';
			break;

		case 'delete': /******************************************************************************** DELETE *********************/
			$ok 	= $db->Execute("delete from publicaciones where id='$id' and categoria_id='$categoria_id'");
			if ($ok) { $_SESSION['Msg'] = 'La publicacion se elimin&oacute; correctamente.';
			} else { $_SESSION['Msg'] = $cond."<hr>".'ERROR!! No se pudo eliminar la publicacion.';	}
			$accion = 'listar';
			break;
/*
		case 'grabar': /******************************************************************************** GRABARNUEVA ******************** *  /
			include('contenidos_guardar.php');
			break;
*/

	}

	if ($accion=='listar') { /******************************************************************************** LISTAR*********************/

		$cond 		= "select * from newsletter order by orden ASC";
		$rs 		= $db->Execute($cond);
		$Noticias 	= $rs->GetRows();
		include_once('news_listar.html.php');
        
	}
	
	include(RADMIN.'/footer.php');
?>